package com.mike.bdb.model;
import static com.sleepycat.persist.model.Relationship.MANY_TO_ONE;

import java.util.Random;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.lang.builder.EqualsBuilder;

import com.sleepycat.persist.model.Entity;
import com.sleepycat.persist.model.PrimaryKey;
import com.sleepycat.persist.model.SecondaryKey;

@Entity
public class Item {

	@PrimaryKey
	private String id;
	
	@SecondaryKey(relate = MANY_TO_ONE)
	private long playerId;

	public void setPlayerId(long playerId) {
		this.playerId = playerId;
	}

	@SecondaryKey(relate = MANY_TO_ONE)
	private int articleId;
	
	public void setArticleId(int articleId) {
		this.articleId = articleId;
	}

	private int amount;

	private String description;
	
	public void setDescription(String description) {
		this.description = description;
	}

	private static final Random random = new Random();
	public static final AtomicInteger auto = new AtomicInteger(0);
	
	public Item() {
	}
	
	public Item(int playerId, int articleId ) {
		this.playerId = playerId;
		this.articleId = articleId;
		this.amount = random.nextInt(10);
		this.description = UUID.randomUUID().toString();
	}
	
	public int getAmount() {
		return amount;
	}

	public int getArticleId() {
		return articleId;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	public String getId() {
		return id;
	}

	public long getPlayerId() {
		return playerId;
	}
	
	public void setAmount(int amount) {
		this.amount = amount;
	}
	
	public String getDescription() {
		return description;
	}
	
	public boolean equals(Object other) {
		return EqualsBuilder.reflectionEquals(this, other);
	}

}
